package com.baigt.juc.base;

import java.util.concurrent.TimeUnit;

/**
 * 类功能描述:
 * Demo1和2会是什么执行结果？
 * 具体说明一下？
 *
 * @author baigt
 * @version V1.0
 * @since 2019-10-15 11:16
 */
public class ThreadRun02 {
    /**
     * thread state is different ,demo1 is dupl start,demo2 is thread is alerady deaded
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
//        demo1();
        System.out.println("----------------------------");
                demo2();
    }

    public static void demo1() throws Exception {
        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
        //又启动一次
        thread.start();
    }

    public static void demo2() throws Exception {
        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
        TimeUnit.SECONDS.sleep(3);
        //又启动一次
        thread.start();
    }
}
